<template>
  <div id="home">
    <div id="app">
      <div id="appTop">
        <div class="appTop_lets">
          <div>
            <span
              data-v-6764ce0f
              class-name="card-panel-icon"
              class="el-icon-user-solid"
              style="font-size: 48px;"
            ><i ></i> </span>
          </div>
          <div class="appTop_quantity" style="height:50px;">
            <p>商品数量</p>
            <countTo :startVal="startVal" :endVal="endVal" :duration="3000"></countTo>
          </div>
        </div>
        <div class="appTop_lets">
          <div>
            <span
              data-v-6764ce0f
              class-name="card-panel-icon"
              class="el-icon-chat-dot-square"
              style="font-size: 48px;"
            ></span>
          </div>
          <div class="appTop_quantity" >
            <p>未发货单</p>
            <countTo :startVal="startVal" :endVal="end" :duration="3000"></countTo>
          </div>
        </div>
      </div>
      <div id="main" style="width:50%;height:400px;"></div>
      <div id="mainline" style="width:50%;height:400px;"></div>
      <div id="mainpie" style="width:20%;height:400px;"></div>
      <div id="mainp" style="width:20%;height:400px;"></div>
    </div>
  </div>
</template>

<script>
import countTo from "vue-count-to";
import dashboard from "@/api/dashboard.js";
export default {
  components: { countTo },
  name: "app",
  data() {
    return {
      active: "",
      mouse:'',
      startVal: 0,
      endVal: 26,
      end: 17,
      array: {
        area: [],
        channel: [],
        daysOrder: [],
        daysSum: [] //时间
      }
    };
  },
  mounted() {
    console.log(this.array);
    var that = this;
    dashboard.home().then(function(res) {
      for (const key in that.array) {
        that.array[key] = res.data.data[key];
      }
      that.drawChart();
      that.mainline();
      that.mainpie();
      that.mainp();
    });
  },
  methods: {  
    drawChart() {
      // 基于准备好的dom，初始化echarts实例
      let myChart = this.$echarts.init(document.getElementById("main"));
      // 指定图表的配置项和数据

      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption({
        title: {
          text: "7月订单"
        },
        tooltip: {},
        legend: {
          right: 'right',
          data: ["订单数"]
        },
        xAxis: {
          data: this.array.daysOrder[0]
        },
        yAxis: {},
        series: [
          {
            name: "订单数",

            type: "bar",
            itemStyle: {
              normal: {
                color: "#00C7FF"
              }
            },
            barWidth: 30, //柱图宽度
            data: [900, 920, 850, 850, 1200, 1210, 1205]
          }
        ]
      });
    },
    mainline() {
      // 基于准备好的dom，初始化echarts实例
      let myCharts = this.$echarts.init(document.getElementById("mainline"));
      // 指定图表的配置项和数据

      // 使用刚指定的配置项和数据显示图表。
      myCharts.setOption({
        title: {
          text: "7日成交金额"
        },
        tooltip: {},
        xAxis: {
          data: this.array.daysSum[0]
        },
        legend: {
        right: 'right',
        data: ['订单数']
    },
        yAxis: {
          type: "value"
        },
        yAxis: {},
        series: [
          {
            color: "#20B2AA",
            name: '订单数',
            data: [820, 932, 901, 934, 1290, 1330, 1320],
            type: "line",
          }
        ]
      });
    },
    mainpie() {
      // 基于准备好的dom，初始化echarts实例
      let myCharts = this.$echarts.init(document.getElementById("mainpie"));
      // 指定图表的配置项和数据

      // 使用刚指定的配置项和数据显示图表。
      myCharts.setOption({
        title: {
          text: "订单地区分布"
        },
        tooltip: {},
        legend: {
        orient: 'vertical',
        right: 'right',
        data: ['地区发布']
    },
        series: [
          {
            name:'地区发布',      
          
            data: this.array.area,
          
            type: "pie"
          }
        ]
      });
    },
    mainp() {
      // 基于准备好的dom，初始化echarts实例
      let myCharts = this.$echarts.init(document.getElementById("mainp"));
      // 指定图表的配置项和数据

      // 使用刚指定的配置项和数据显示图表。
      myCharts.setOption({
        title: {
          text: "订单渠道分布"
        },
        tooltip: {},
        legend: {
          data: ["订单号"]
        },

        series: [
          {
            data: this.array.channel,
            type: "pie"
          }
        ]
      });
    }
  }
};
</script>
<style scoped>
#home {
  width: 100%;
  height: 0px;
  background: #f0f2f5;
}
#app {
  width: 80vw;
  height: 100vh;
  margin: auto;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}
.el-icon-user-solid {
  line-height: 100px;
}
.appTop_quantity {
  padding-top: 30px;
}
.appTop_quantity p {
  line-height: 18px;
  color: rgba(0, 0, 0, 0.45);
  font-size: 16px;
  margin-bottom: 12px;
}
.appTop_quantity span {
  color: #666;
  font-size: 20px;
  width: 50px !important;
  height: 50px !important;
}
#app > div {
  width: 50%;
}
.appTop_lets {
  width: 200px;
  height: 100px;
  display: flex;
  justify-content: space-around;
  background: #ffffff;
  margin-bottom: 50px;
  background: #f0f2f5;
}

.appTop_quantity {
  height: 50px;
}
.el-icon-chat-dot-square {
  color: #36a3f7;
  margin: 20px 0px;
}
.el-icon-user-solid {
  color: #40c9c6;
  line-height: 100px;
}
.el-icon-user-solid:hover{ color:#7AB900;}
.el-icon-chat-dot-square:hover{ color:#7AB900;}
</style>